<template>
  <div class="purse_detail">
    <div class="detail_header">
      <top-bar :barObj="barObj"/>
      <div class="icon">
        <img v-if="type=='PS'" :src="currency['PS']" alt>
        <img v-else :src="currency[lockMoney.value1]" alt>
      </div>
      <div class="name" v-if="lockMoney.value1=='章鱼丸'">PS</div>
      <div class="name" v-else>{{lockMoney.value1}}</div>

      <div class="num">可转出资产</div>
      <div class="number">{{lockMoney.value2}}</div>
    </div>
    <div class="detail_content">
      <div class="title" v-if="type!='PS'">目前只支持 ocx.com 交易所提币</div>
      <template v-if="type!='PS'">
        <div class="warp">
          <div class="txt">X 网交易所账号</div>
          <input type="text" v-model="val1">
          <div class="txt">转出数量</div>
          <input type="text" v-model="val2">
          <div class="txt">登陆密码</div>
          <input type="text" v-model="val3">
        </div>
      </template>
      <template v-if="type=='PS'">
        <div class="warp">
          <div class="txt">
            <ul>
              <li :class="{'li-active':idOrAddr=='id'}" @click="idOrAddress('id')">游戏ID</li>
              <li :class="{'li-active':idOrAddr=='addr'}" @click="idOrAddress('addr')">转出地址</li>
            </ul>
          </div>
          <input type="text" v-model="MC">
          <div class="txt">转出数量</div>
          <input type="text" style="width:70%" v-model="YJELQss">
          <span>手续费 3%</span>
          <!-- <div class="txt">登陆密码</div>
          <input type="password" style="width:70%" v-model="YJEYhNew">-->
        </div>
      </template>
      <div class="btn" @click="confirm(lockMoney)">转 出</div>
      <!-- <div class="btn" @click="Rollout1(lockMoney)">转 出</div> -->
      <!-- Rollout1 -->
      <!-- confirm(lockMoney) -->
    </div>

    <div class="rolloff-popup" v-if="isPopup">
      <div class="popup">
        <div class="title">
          <i @click="closeMask" class="iconfont icon-guanbi"></i> 确认转出
        </div>
        <div class="txt" v-if="idOrAddr=='id'">{{tsTxt}}</div>
        <div class="txt" v-else>你确定向{{MC}}转出{{YJELQss}}吗</div>
        <div class="btn" @click="sureConfirm">确 认</div>
      </div>
    </div>

    <div class="payMask" v-if="isPayMask">
      <div class="mian">
        <div class="title">
          <i @click="closeMask" class="iconfont icon-guanbi"></i> 请输入支付密码
        </div>
        <div class="content">
          <div class="p">
            <div class="txt" v-if="idOrAddr=='id'">{{tsTxt}}</div>
            <div class="txt" v-else>你确定向{{MC}}转出{{YJELQss}}吗</div>
          </div>
          <div class="txt">
            <span class="ps">PS</span>
            <span>{{YJELQss}}</span>
          </div>
        </div>
        <div class="inputBox inputBox1" ref="inputBox">
          <input type="password" maxlength="6" v-model="passwordVal">
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import topBar from "@/components/topBar";
import { GetLock, GetDhZyWByUser, GetZsSendByPSFun } from "../../api";
import { mapGetters } from "vuex";
import { Toast } from "mint-ui";
import { getGuid } from "../../utils/index";
import { hex_md5 } from "../../utils/md5";

export default {
  name: "purseDetail",
  data() {
    return {
      isPopup: false,
      isPayMask: false,
      val: 0,
      val1: "",
      val2: "",
      val3: "",
      YJELQss: "",
      MC: "",
      YJEYhNew: "",
      barObj: {
        isBack: true,
        backVal: "钱包",
        title: "转 出",
        isIcon: true
      },
      type: this.$route.query.type,
      idOrAddr: "id",
      lockMoney: {},
      id: localStorage.zyUserId,
      tsTxt: "",
      pwsVal: "",
      pws1: "",
      pws2: "",
      pws3: "",
      pws4: "",
      pws5: "",
      pws6: "",
      passwordVal: ""
    };
  },
  components: { topBar },
  watch: {},
  mounted() {
    this.getLockMoney();
    // if (this.isPayMask) {
    //   this.inputWrite();
    // }
  },
  computed: {
    ...mapGetters(["currency"])
  },
  watch: {
    passwordVal(v1, v2) {
      if (v1.length == 6) {
        // this.payFun();
        console.log("输入完成");
        this.isPayMask = false;
        this.isPopup = false;
        if (this.idOrAddr != "addr") {
          this.toGameID();
        } else {
          this.sure_Confirm();
        }
      }
    }
  },
  methods: {
    key_dow() {
      this.inputWrite();
    },
    Rollout1(data) {
      console.log(this.idOrAddr);
      if (data.value1 == "章鱼丸") {
        this.toGameID(0);
        this.isPayMask = true;
      } else {
        Toast({
          message: "此功能暂未开通！"
        });
      }
    },
    getLockMoney() {
      GetLock({
        ID: this.id,
        MC: this.$route.query.type
      }).then(res => {
        this.lockMoney = res.data.EntityList[0];
      });
    },
    idOrAddress(i) {
      this.idOrAddr = i;
    },
    confirm(data) {
      if (data.value1 == "章鱼丸") {
        //ID
        if (this.idOrAddr != "addr") {
          this.toGameID(0);
          this.isPopup = true;
        } else {
          //Addr
          if (!this.MC || !this.YJELQss) {
            Toast({
              message: "请填写相应字段！"
            });
            return;
          }
          this.isPopup = true;
        }
      } else {
        Toast({
          message: "此功能暂未开通！"
        });
      }
    },
    closeMask() {
      this.isPopup = false;
      this.isPayMask = false;
    },
    sureConfirm() {
      this.isPopup = false;
      this.passwordVal = "";
      this.isPayMask = true;
    },
    sure_Confirm() {
      console.log(this.passwordVal);
      // this.YJEYhNew =  this.pwsVal
      if (this.idOrAddr == "addr") {
        GetDhZyWByUser({
          ID: this.id,
          YJELQss: this.MC,
          LoginMachine: getGuid(),
          MC: this.YJELQss,
          YJEYhNew: hex_md5(this.passwordVal)
        }).then(res => {
          this.isPopup = false;
          Toast({
            message: res.data.Content
          });
          if (res.data.MessageID == "0") {
            this.getLockMoney();
          }
          this.pws1 = "";
          this.pws2 = "";
          this.pws3 = "";
          this.pws4 = "";
          this.pws5 = "";
          this.pws6 = "";
        });
      } else {
        this.toGameID();
      }
      this.isPopup = !this.isPopup;
    },
    toAddress() {
      GetDhZyWByUser({
        ID: this.id,
        YJELQss: this.MC,
        LoginMachine: getGuid(),
        MC: this.YJELQss,
        YJEYhNew: hex_md5(this.passwordVal)
      }).then(res => {
        Toast({
          message: res.data.Content
        });
        if (res.data.MessageID == "0") {
          this.getLockMoney();
        }
      });
    },

    //通过gameid
    toGameID(data) {
      {
        console.log(this.passwordVal);
        let zhi;
        if (data == "0") {
          zhi =
            "China_Zhejiang_Hangzhou_Xihu_Gucun_912Yule" +
            "MC," +
            this.MC +
            ";LoginMachine," +
            getGuid() +
            ";YJEYhOld," +
            2 +
            ";RegType," +
            data +
            ";ID," +
            this.id +
            ";YJELQss," +
            this.YJELQss +
            ";YJEYhNew," +
            hex_md5(this.passwordVal) +
            ";China_Zhejiang_Hangzhou_Xihu_Gucun_912Yule";
        } else {
          zhi =
            "China_Zhejiang_Hangzhou_Xihu_Gucun_912Yule" +
            "MC," +
            this.MC +
            ";LoginMachine," +
            getGuid() +
            ";YJEYhOld," +
            2 +
            ";ID," +
            this.id +
            ";YJELQss," +
            this.YJELQss +
            ";YJEYhNew," +
            hex_md5(this.passwordVal) +
            ";China_Zhejiang_Hangzhou_Xihu_Gucun_912Yule";
        }
        GetZsSendByPSFun({
          ID: this.id,
          MC: this.MC,
          YJELQss: this.YJELQss,
          LoginMachine: getGuid(),
          YJEYhNew: hex_md5(this.passwordVal),
          JYEPass: this.$md5(zhi).toUpperCase(),
          YJEYhOld: 2,
          RegType: data
        }).then(res => {
          if (data == "0") {
            this.tsTxt = res.data.Content;
          } else {
            // this.getLockMoney();
            Toast({
              message: res.data.Content
            });
          }
          this.getLockMoney();
          this.pws1 = "";
          this.pws2 = "";
          this.pws3 = "";
          this.pws4 = "";
          this.pws5 = "";
          this.pws6 = "";
          // if (res.data.MessageID != "0") {
          //   this.isPopup = false;
          // } else {
          //   this.isPopup = true;
          // }
        });
      }
    },
    getVal() {
      this.pwsVal =
        this.pws1 + this.pws2 + this.pws3 + this.pws4 + this.pws5 + this.pws6;
    },
    inputWrite(txts) {
      if (!this.$refs.inputBox) {
        return;
      }
      var txts = this.$refs.inputBox.getElementsByTagName("input");
      let _this = this;
      for (var i = 0; i < txts.length; i++) {
        var t = txts[i];
        t.index = i;
        t.setAttribute("readonly", true);
        t.onkeyup = function() {
          this.value = this.value.replace(/^(.).*$/, "$1");
          var next = this.index + 1;
          if (next > txts.length - 1) {
            console.log("提交");
            _this.isPayMask = false;
            _this.isPopup = false;
            _this.getVal();

            if (_this.idOrAddr != "addr") {
              alert("id");
              // _this.toGameID();
            } else {
              alert("addr");
              // _this.toAddress();
              // _this.sure_Confirm();
            }
          }
          if (txts[next] == undefined) {
            return;
          }
          txts[next].removeAttribute("readonly");
          txts[next].focus();
        };
      }
      txts[0].removeAttribute("readonly");
    }
  }
};
</script>
<style lang="stylus" scoped>
.purse_detail {
  height: 100%;
  position: relative;

  .payMask {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    position: fixed;
    top: 0;
    left: 0;

    .mian {
      width: 7.04rem;
      height: 7.1rem;
      background: #FFF;
      border-radius: 0.2rem;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;

      .title {
        width: 6.67rem;
        line-height: 1.08rem;
        border-bottom: 1px solid rgba(230, 230, 230, 1);
        margin: 0 auto;
        font-size: 16px;
        font-weight: 500;

        i {
          float: left;
        }
      }

      .content {
        width: 6.63rem;
        height: 3rem;
        margin: 0.5rem auto;
        border-bottom: 1px solid rgba(137, 137, 137, 1);
        text-align: center;
        box-sizing: border-box;
        padding-top: 0.5rem;

        .p {
          margin: 0.3rem auto;
          font-size: 14px;
        }

        .txt {
          font-weight: 500;

          .ps {
            font-size: 30px;
            display: inline-block;
            position: relative;
            bottom: 5px;
          }

          span {
            font-size: 40px;
          }
        }
      }

      .inputBox {
        width: 6.32rem;
        height: 0.93rem;
        display: flex;
        margin: 0.07rem auto;

        input {
          width: 1.03rem;
          flex: 1;
          border: 1px solid rgba(203, 203, 203, 1);
          text-align: center;
        }
      }

      .inputBox1 {
        input {
          width: 100%;
          text-align: left;
          letter-spacing: 0.81rem;
          padding-left: 0.5rem;
        }
      }
    }
  }

  .rolloff-popup {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    position: fixed;
    top: 0;
    left: 0;

    .popup {
      width: 7.07rem;
      height: 8.42rem;
      background: #FFF;
      border-radius: 0.2rem;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;

      .title {
        width: 6.67rem;
        line-height: 1.08rem;
        border-bottom: 1px solid rgba(230, 230, 230, 1);
        margin: 0 auto;
        font-size: 16px;
        font-weight: 500;

        i {
          float: left;
        }
      }

      .txt {
        width: 70%;
        margin: 80px auto;
        font-size: 20px;
        line-height: 0.6rem;
      }

      .btn {
        width: 6.18rem;
        line-height: 1.01rem;
        margin: 20px auto 10px auto;
        color: #fff;
        background: linear-gradient(166deg, rgba(193, 107, 51, 1), rgba(255, 99, 44, 1), rgba(255, 133, 44, 1));
        box-shadow: 0px 3px 9px 0px rgba(91, 24, 0, 0.47);
        border-radius: 10px;
        text-align: center;
      }
    }
  }

  .detail_header {
    height: 6.39rem;
    background: linear-gradient(90deg, rgba(0, 174, 255, 1), rgba(0, 180, 255, 1), rgba(0, 120, 255, 1));
    padding-top: 0.7rem;
    color: #fff;
    text-align: center;

    .topBar {
      display: flex;
      text-align: center;
      justify-content: space-around;
      color: #fff;

      .bar {
        flex: 1;
        margin: 0 20px;
        font-size: 17px;
      }

      .bar:nth-child(1) {
        text-align: left;
        font-size: 15px;
      }

      .bar:nth-child(3) {
        text-align: right;
      }
    }

    .icon {
      width: 0.9rem;
      height: 0.9rem;
      margin: 30px auto 10px auto;

      img {
        width: 100%;
      }
    }

    .name {
      font-size: 27px;
    }

    .number {
      font-size: 33px;
    }

    .num {
      font-size: 16px;
      opacity: 0.7;
      margin: 20px 0;
    }
  }

  .detail_content {
    width: 7.07rem;
    background: #fff;
    border-radius: 20px;
    padding: 20px 0;
    box-sizing: border-box;
    margin: 0 auto 10px auto;
    position: relative;
    top: -55px;

    .title {
      height: 32px;
      font-size: 16px;
      font-weight: 500;
      color: rgba(97, 97, 97, 1);
      text-align: center;
    }

    .warp {
      width: 6.18rem;
      margin: 0 auto;

      span {
        color: #616161;
      }

      .txt {
        color: #006AEE;
        font-size: 16px;
        margin: 5px auto 0px 20px;

        ul {
          font-size: 16px;

          li {
            width: 30%;
            float: left;
            text-align: center;
            line-height: 0.5rem;
            background: #E8E8E8;
            border-radius: 10px;
            color: #616161;
          }

          .li-active {
            background: #006AEE;
            color: #fff;
          }
        }
      }

      input {
        width: 6.18rem;
        height: 0.7rem;
        line-height: 0.7rem;
        background: #E8E8E8;
        font-size: 20px;
        box-sizing: border-box;
        margin: 8px auto;
        padding: 0 20px;
        border-radius: 8px;
      }
    }

    .btn {
      width: 6.18rem;
      line-height: 1.01rem;
      margin: 20px auto 10px auto;
      color: #fff;
      background: linear-gradient(166deg, rgba(193, 107, 51, 1), rgba(255, 99, 44, 1), rgba(255, 133, 44, 1));
      box-shadow: 0px 3px 9px 0px rgba(91, 24, 0, 0.47);
      border-radius: 10px;
      text-align: center;
    }
  }

  .pfooter {
    position: fixed;
    bottom: 0;
    left: 0;
  }
}
</style>

